<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>day06_demo01</title>
<script>
	function jc(){
		//获取文本框内的值
		var n=document.getElementById("num").value;
		var span=document.getElementById("result");
		var sum=1;
		if(isNaN(n)){
			span.innerHTML="不是数字";
			
		}else{
			if(n==0){
				span.innerHTML=1;
			}else if(n<0){
				span.innerHTML="输入的数字是一个负数："+n+"没有阶乘";
			}else{
				while(n>=1){
					sum=sum*n	
					n--;
				}
				span.innerHTML=sum;
			}
		}		
				
		
		
	}
	
</script>

<style>
	#num{
		text-align:center;
		
	}
	

</style>

</head>
<body>
	<input type="text" id="num"/>
	<input type="button" value="求阶乘"
		onclick="jc();"/>
	=<span id="result"></span>



</body>
</html>